package com.scqkxx.gamebox.activity.myself;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.scqkxx.gamebox.R;

public class prefrenceView extends RelativeLayout {

    private String leftText,rightText,centerText;
    private int rightImageResId;
    private RelativeLayout mPreferenceView;
    private TextView tv_left,tv_right,tv_center;
    private ImageView im_right;

    public prefrenceView(Context context) {
        super(context);
    }

    public prefrenceView(Context context, @Nullable AttributeSet attrs) {
        super(context,attrs);

        TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.preferenceStyle);
        leftText = array.getString( R.styleable.preferenceStyle_leftText );
        rightText = array.getString( R.styleable.preferenceStyle_rightText  );
        rightImageResId = array.getInt( R.styleable.preferenceStyle_rightIcon ,R.mipmap.arrow_right);
        centerText = array.getString( R.styleable.preferenceStyle_centerText  );

        mPreferenceView = (RelativeLayout) LayoutInflater.from(getContext()).inflate( R.layout.layout_preference,null,false);
        int h = mPreferenceView.getHeight();
        tv_left =  mPreferenceView.findViewById(R.id.tv_left );
        tv_right = mPreferenceView.findViewById(R.id.tv_right );
        im_right = mPreferenceView.findViewById(R.id.im_right);
        addView(mPreferenceView , new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT , ViewGroup.LayoutParams.WRAP_CONTENT));

        //setBackgroundColor(getResources().getColor(R.color.white));
        setBackgroundResource(R.drawable.click_ripple);
//        if (TextUtils.isEmpty(leftText)) {
//            TextView tvleft = new TextView(getContext());
//            tvleft.setPadding(getResources().getDimensionPixelSize(R.dimen.dp_10),0,0,0);
//            addView(tvleft);
//        }
        tv_left.setText(leftText);

        if (!TextUtils.isEmpty(rightText)) {
            tv_right.setVisibility(VISIBLE);
            tv_right.setText(rightText);
        }
        im_right.setImageResource(rightImageResId);

        int e = mPreferenceView.getHeight();
        array.recycle();
    }


    public prefrenceView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    public prefrenceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public String getLeftText() {
        return leftText;
    }

    public void setLeftText(String leftText) {
        this.leftText = leftText;
    }

    public String getRightText() {
        return rightText;
    }

    public void setRightText(String rightText) {
        this.rightText = rightText;
        if (!TextUtils.isEmpty(rightText)) {
            tv_right.setVisibility(VISIBLE);
            tv_right.setText(rightText);
        }
        // invalidate();
    }
//    @Override
//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//    }
//
//    @Override
//    protected void onLayout(boolean changed, int l, int t, int r, int b) {
//        super.onLayout(changed, l, t, r, b);
//    }
//
//    @Override
//    protected void onDraw(Canvas canvas) {
//        super.onDraw(canvas);
//    }
}
